package com.petplanet.navigation

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.petplanet.R

@Composable
fun NavApp(){
    val navController = rememberNavController()
    val startDestination = Destinations.BlogPage
    var currentDestination: Destinations by remember { mutableStateOf(startDestination) }


    Scaffold(
        modifier = Modifier.fillMaxSize(),
        bottomBar = {
            NavigationBar(){
                Destinations.getBottomNavEntries().forEach {
                    NavigationBarItem(
                        selected = currentDestination.route == it.route,
                        onClick = { currentDestination = it },
                        icon = {
                            Icon(
                                painterResource(id = it.iconResID?: R.drawable.default_image),
                                contentDescription = it.title)
                               },
                        label = { Text(text = it.title) }
                    )
                }

            }
        }
    ) {
        NavHost(
            modifier = Modifier.padding(it),
            navController = navController,
            startDestination = startDestination.route
        ){
            composable(currentDestination.route) {
                Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center){
                    currentDestination.page()
                }
            }

        }
    }



}